export function getQuery(search = window.location.search) { const query: Record<string, any> = {}
const searchH = search[0] === '?' ? search.substr(1) : search
searchH.split('&').forEach((str) => { const strArr = str.split('=') const key = strArr[0]
if (!key) return
const val = decodeURIComponent(strArr[1]) query[key] = val }) return query}
export function toSearch<T = Record<string, any>>(obj: T, hasQuestionMark = false) { const arr = Object.keys(obj).map((key) => { let val = obj[key]
if (typeof val !== 'string') { try { val = JSON.stringify(val) } catch (err) { console.error(err) } }
return `${key}=${encodeURIComponent(val)}` })
return (hasQuestionMark ? '?' : '') + arr.join('&')}